package fpTree;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  Sorts items by decreasing frequency
 */
public class FListComparator implements Comparator<Integer> {
	private Map<Integer, Integer> itemFreqs;
	
	public FListComparator(Map<Integer, Integer> itemFreqs) {
		this.itemFreqs = itemFreqs;
	}
	
	@Override
	public int compare(Integer s1, Integer s2) {
//		System.out.println("comparing: " + s1 + " " + s2 + " with frequencies " + itemFreqs.get(s1) + " " + itemFreqs.get(s2));
		int a = this.itemFreqs.get(s1);
		int b = this.itemFreqs.get(s2);
		if (a == b)
			return s1 - s2;
		else
			return this.itemFreqs.get(s2) - this.itemFreqs.get(s1); 
	}

}
